<!--
 * 楼栋表
 * @author ZhuanZ（无密码）
 * @date 2025-01-10
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
-->
<template>
  <edit-container ref="containerRef" v-bind="containerConfig">
    <lg-form ref="formRef" v-loading="loading" :schema="schema" v-bind="formConfig"> </lg-form>
  </edit-container>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { EditContainer, useEditContainer } from '@/components';
import { LgForm } from '@/soar';
import api, { subject } from './api';
import schema from './schema';

const emits = defineEmits(['ok']);

const containerRef = ref();
const formRef = ref();
const { containerConfig, formConfig, loading, open } = useEditContainer<any>({
  header: subject,
  containerRef,
  formRef,
  getData: (params: any) => api.detail(params.id),
  onOk: async ({ values, data, params, isUpdate, changed }) => {
    if (changed) {
      values.id = data.id;
      await api.saveOrUpdate(values, isUpdate);
      emits('ok', values);
    }
  },
  containerProps: {
    width: '500px',
  },
});

defineExpose({ open });
</script>
